﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NangLuongTieuDiemGUI.NangLuongTieuDiemUserControl;
using NangLuongTieuDiemDTO.DTO;
using NangLuongTieuDiemBUS;

namespace NangLuongTieuDiemGUI.NangLuongTieuDiemForms
{
    public partial class frmShowInfomation : DevExpress.XtraEditors.XtraForm
    {
        #region "[loại sản phẩm]"
        enum Type
        { 
            Pin,
            Acquy,
            DieuKhienSac,
            ThietBiDien,
            BoKichDien

        }
        private Type GetType(int _Type)
        {
            try {
                switch (_Type)
                { 
                    case 0:
                        return Type.Pin;
                    case 1:
                        return Type.Acquy;
                    case 2:
                        return Type.DieuKhienSac;
                    case 3:
                        return Type.ThietBiDien;
                    case 4:
                        return Type.BoKichDien;

                }
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("GetType", ex);
            }
            return  Type.Pin;
        }
        #endregion

        #region "[khởi tạo]"
        public frmShowInfomation()
        {
            InitializeComponent();
        }
        int  i = 0;
        List<string> lis = new List<string>();
        public frmShowInfomation(List<string> listString, int id)
        {
            lis = listString;
            i = id;
            InitializeComponent();
        }
        #endregion

        #region "[Load]"
        private void frmShowInfomation_Load(object sender, EventArgs e)
        {
            try {
                labelControl1.Text = lis[0];
                labelControl2.Text = lis[1];
                labelControl3.Text = lis[2];
                labelControl4.Text = lis[3];
                labelControl5.Text = lis[4];
                switch (GetType(i))
                {
                    case Type.Pin://9 lable
                        labelControl6.Text = lis[5];
                        labelControl7.Text = lis[6];
                        labelControl8.Text = lis[7];
                        labelControl9.Text = lis[8];
                        break;
                    case Type.Acquy://5 lable

                        labelControl6.Visible =
                        labelControl7.Visible =
                        labelControl8.Visible =
                        labelControl9.Visible = false;
                        break;
                    case Type.DieuKhienSac:
                        labelControl6.Visible = 
                        labelControl7.Visible = 
                        labelControl8.Visible = 
                        labelControl9.Visible = false;
                        break;
                    case Type.ThietBiDien:
                        labelControl6.Text = lis[5];
                        labelControl7.Text = lis[6];
                        labelControl8.Visible = labelControl9.Visible = false;
                        break;
                    case Type.BoKichDien:
                        break;
                    default:
                        labelControl1.Visible =
                        labelControl2.Visible =
                        labelControl3.Visible =
                        labelControl4.Visible =
                        labelControl5.Visible =
                        labelControl6.Visible =
                        labelControl7.Visible =
                        labelControl8.Visible =
                        labelControl9.Visible = false;

                        break;

                }
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("frmShowInfomation_Load", ex);
            }
            

            pictureEdit1.Image = imageCollection1.Images[0];
            labelControl1.Text = lis[0];
        }
        #endregion

        #region "[Thoát]"
        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region "[chọn]"
        private void btnChon_Click(object sender, EventArgs e)
        {
            try 
            { 
                //hiển thị ngược lại listview
                ucLapHoaDonBanHang.m_IDSelect = true;
                this.Close();
            }
            catch (Exception ex) 
            {
                InSert_LoiHeThong("btnChon_Click", ex);
            }
        }
        #endregion

        #region "[Hàm insert lỗi hệ thống]"
        public void InSert_LoiHeThong(string TenHam, Exception ex)
        {
            LoiHeThongDTO lhtDto = new LoiHeThongDTO();
            lhtDto.TenLoi = ex.Message.ToString();
            lhtDto.NgayTao = DateTime.Now;
            lhtDto.TenHamBiLoi = "frmShowInfomation_" + TenHam;
            lhtDto.SuaLoi = false;
            lhtDto.GhiChu = "";
            NangLuongTieuDiem_Management.LoiHeThong_Insert(lhtDto);
            MessageBox.Show(lhtDto.TenLoi);
        }
        #endregion
    }
}